using System;
using System.Data;
using TimeSheetDAL;

namespace TimeSheetBLL
{
    [Table("project")]
    [PrimaryKeyAttribute("project_id", "ID")]
    [ColumnAttribute("project_name", "Name")]
    [ColumnAttribute("client_id", "ClientID")]
    [ColumnAttribute("status_id", "StatusID")]
    [ColumnAttribute("active", "Active")]
    public class Project : IDBEntity
    {
        private string name;
        private int clientID;
        private int statusID;
        private bool active;
        private long iD;

        private Client client;

        public Project()
        {
            active = true;
            client = new Client();
        }

        public Client ProjectClient
        {
            get
            {
                BrokerFactory.Fill(client);
                return client;
            }
        }

        public static DataTable GetAllStaffVisibleProjects()
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetAllPublicProjects();
        }

        public double GetTotalHoursByPayPeriod(DateTime date)
        {
            DBFacade dbf = new DBFacade();
            return
                dbf.GetTotalProjectHoursByDate(
                    iD, Utils.GetPayPeriodStart(date), Utils.GetPayPeriodEnd(date));
        }

        public double GetTotalHoursByDateRange(DateTime from, DateTime to)
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetTotalProjectHoursByDate(iD, from, to);
        }

        public double GetTotalHours()
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetTotalProjectHours(iD);
        }

        public DataTable GetAllHours()
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetAllProjectHours(iD);
        }

        public DataTable GetChargeableHoursByPayPeriod(DateTime date)
        {
            DBFacade dbf = new DBFacade();
            return
                dbf.GetChargeableProjectHours(
                    iD, Utils.GetMonthStart(date), Utils.GetMonthEnd(date));
        }

        public DataTable GetChargeableHoursByDateRange(DateTime from, DateTime to)
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetChargeableProjectHours(iD, from, to);
        }

        public static DataTable GetProjectHoursForSummaryByDate(
            DateTime start, DateTime end)
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetProjectHoursForSummaryByDate(start, end);
        }

        public static DataTable GetProjectTotalHoursByDate(DateTime start, DateTime end)
        {
            DBFacade dbf = new DBFacade();
            return dbf.GetProjectTotalHoursByDate(start, end);
        }

        #region Generated

        public long ID
        {
            get { return iD; }
            set { iD = value; }
        }

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        public long ClientID
        {
            get { return client.ID; }
            set { client.ID = value; }
        }

        public int StatusID
        {
            get { return statusID; }
            set { statusID = value; }
        }

        public bool Active
        {
            get { return active; }
            set { active = value; }
        }

        #endregion
    } //class
} //namespace
